<template>
  <div class="login-way">
    <el-form :model="registerForm">
      <el-form-item>
        <el-input v-model="registerForm.username" placeholder="请输入用户名" />
      </el-form-item>
      <el-form-item class="password-item">
        <el-input v-model="registerForm.password" type="password" placeholder="请输入密码" />
      </el-form-item>
      <el-form-item class="password-item">
        <el-input v-model="registerForm.telephone" placeholder="请输入手机号" />
      </el-form-item>
    </el-form>
    <div class="login-btn" @click="handleRegisterClick">
      注册
    </div>
  </div>
</template>
<script>
import { mapMutations } from 'vuex'
import { userRegister } from 'api/user.js'
import { ERR_OK } from 'api/config.js'
export default {
  data () {
    return {
      registerForm: {
        username: '',
        password: '',
        telephone: ''
      }
    }
  },
  methods: {
    // 注册点击事件
    handleRegisterClick () {
      userRegister(this.registerForm).then(res => {
        let { code, data } = res
        if (code !== ERR_OK) {
          this.$message.error(res.msg)
          return false
        }
        this.$message.success('注册成功，快去登录吧！')
        this.registerForm = {}
      })
    },
    // vuex
    ...mapMutations('login', {
      'setUserInfo': 'SET_USER_INFO',
      'setShowLogin': 'SET_SHOW_LOGIN'
    })
  }
}
</script>
<style lang="stylus" scoped>
  @import '~assets/stylus/login-form.styl';

  .login-way
    .agreement
      color: #37f;
      cursor: pointer;
    >>> .el-checkbox__label
      color: #9199a1!important;
</style>
